$(function () {
    searchKeyword($(".form_button"),$(".h_input"));
    tip($(".h_input"),$(".tip"),$(".form_button"));
    $.get("/car/car_count",function (data) {
        if(data.carcount != 0){
            $(".shopping-amount").html(data.carcount);
        }
    });
    // 类别收起功能
    var url  = window.location.pathname.split("/");
    $(".classify .right>div:last-child a").on("click",function () {
        var $right =$(".classify .right");
        if($right.hasClass("right_inner_min")){
            $right.removeClass("right_inner_min");
            $(this).html("收起");
        }else{
            $right.addClass("right_inner_min");
            $(this).html("展开");
        }
    });
    $.get("/commodity/findAllType",function (data) {
        var $ul = $(".right_inner>ul");
        $ul.empty();
        $("<li><a href=\"\"></a></li>").find("a").html("全部").attr("href",window.location.pathname).end().appendTo($ul);
        $.each(data,function (index,element) {
            $("<li><a href=\"\"></a></li>").find("a").html(element[1]).attr("href","?type="+element[0]).end()
                .appendTo($ul);
        });

    });
    var q = url[url.length - 1];
    if(q != undefined && q != "list"){
        $(".form>input").val(decodeURI(q));
    }

    function getParameter(name) {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }

    $(function(){
        var totalPage = 20;
        var totalRecords = 390;
        var pageNo = getParameter('pno');
        if(!pageNo){
            pageNo = 1;
        }
        kkpager.generPageHtml({
            pno : pageNo,
            //总页码
            total : totalPage,
            //总数据条数
            totalRecords : totalRecords,
            mode : 'click',//默认值是link，可选link或者click
            click : function(n){
                // do something
                //手动选中按钮
                this.selectPage(n);
                return false;
            }
        });
    });
});
